package course.view;

import java.awt.Color;
<<<<<<< HEAD
import java.awt.Dialog.ModalityType;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import course.controller.CourseControllerListener;
import course.po.Teacher;

public class TeacherDialog extends JDialog{
	private static final long serialVersionUID = 1L;
	private CourseControllerListener  courseControllerListener;
	private JButton confirmButton;
	private JPanel teacherAddPanel;
	private Teacher teacher;
	private JTextField teacherIdTextField;
	private JTextField teacherNoTextField;
	private JTextField  teacherNameTextField;
	private JTextField teacherSexTextField;
	private JTextField  teacherAgeTextField;
	private JTextField  courseIdTextField;
	public static JRadioButton radioMan;
	public static JRadioButton radioFemal;
	public TeacherDialog( TeacherJPanel owner, String title, Teacher teacher ){
		this.courseControllerListener = owner.getControllerListener();
		this.courseControllerListener.setTeacherAddDialog(this);
		this.setTitle(title);
		this.teacher = teacher;
		this.add(getTeacherAddPanel());
		this.setModal(true); // 设有模
		this.setModalityType(ModalityType.DOCUMENT_MODAL);//DOCUMENT_MODAL对话框阻止来自同一文档的所有顶级窗口的输入，但来自其自己的子层次结构的窗口除外。
		this.setSize(370, 530);
		this.setLocationRelativeTo(null);
		this.setResizable(false);
		this.setVisible(true);
		this.validate();
	}

	public void closeCurrentDialog() {
		this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);

	}

	/**
	 * 添加/修改表单面板
	 * 
	 * @return
	 */
	private JPanel getTeacherAddPanel() {
		teacherAddPanel = new JPanel();
		teacherAddPanel.setBackground(Color.orange);
		if ("添加教师".equals(this.getTitle())) {
			radioMan = new JRadioButton("男");
			radioFemal = new JRadioButton("女");
			ButtonGroup group = new ButtonGroup();
			group.add(radioMan);
			group.add(radioFemal);
			teacherIdTextField = new JTextField(30);
			teacherNoTextField = new JTextField(30);
			teacherNameTextField = new JTextField(30);
//			teacherSexTextField = new JTextField(30);
			teacherAgeTextField = new JTextField(30);
			teacherAgeTextField = new JTextField(30);
			teacherAgeTextField.addKeyListener(new KeyAdapter() {
				public void keyTyped(KeyEvent e) {
				new FunctionFrame();
				teacherAgeTextField.setText(String.valueOf(FunctionFrame.getSqlDate()));
				}
			});
			courseIdTextField = new JTextField(30);
			confirmButton = new JButton("确定添加");
			confirmButton.setActionCommand("addTeacherPost"); // 添加教师
		} else {
			radioMan = new JRadioButton("男");
			radioFemal = new JRadioButton("女");
			ButtonGroup group = new ButtonGroup();
			group.add(radioMan);
			group.add(radioFemal);
			teacherIdTextField = new JTextField(String.valueOf(teacher.getTeaId()), 30);
			teacherNoTextField = new JTextField(teacher.getTeaNo(), 30);
			teacherNameTextField = new JTextField(teacher.getTeaName(), 30);
//			teacherSexTextField = new JTextField(teacher.getTeaSex(), 30);
			if(teacher.getTeaSex().contentEquals("男")) {
				radioMan.setSelected(true);
			} else {
				radioFemal.setSelected(true);
			}
			teacherAgeTextField = new JTextField(String.valueOf(teacher.getTeaAge()), 30);
			teacherAgeTextField.addKeyListener(new KeyAdapter() {
				public void keyTyped(KeyEvent e) {
				new FunctionFrame();
				teacherAgeTextField.setText(String.valueOf(FunctionFrame.getSqlDate()));
				}
			});
			courseIdTextField = new JTextField(String.valueOf(teacher.getCourse().getCouId()), 30);
			confirmButton = new JButton("确定修改");
			confirmButton.setActionCommand("updateTeacherPost"); // 修改教师
		}
		confirmButton.addActionListener(courseControllerListener);
		teacherAddPanel.add(new JLabel("编号"));
		teacherAddPanel.add(teacherIdTextField);
		teacherAddPanel.add(new JLabel("教职工号"));
		teacherAddPanel.add(teacherNoTextField);
		teacherAddPanel.add(new JLabel("姓名"));
		teacherAddPanel.add(teacherNameTextField);
		teacherAddPanel.add(new JLabel("性别"));
		teacherAddPanel.add(radioMan);
		teacherAddPanel.add(radioFemal);
		teacherAddPanel.add(new JLabel("年龄"));
		teacherAddPanel.add(teacherAgeTextField);
		teacherAddPanel.add(new JLabel("所教科目"));
		teacherAddPanel.add(courseIdTextField);
		teacherAddPanel.add(confirmButton);
		return teacherAddPanel;
	}

	public CourseControllerListener getCourseControllerListener() {
		return courseControllerListener;
	}

	public void setCourseControllerListener(CourseControllerListener courseControllerListener) {
		this.courseControllerListener = courseControllerListener;
	}

	public JButton getConfirmButton() {
		return confirmButton;
	}

	public void setConfirmButton(JButton confirmButton) {
		this.confirmButton = confirmButton;
	}

	public Teacher getTeacher() {
		return teacher;
	}

	public void setTeacher(Teacher teacher) {
		this.teacher = teacher;
	}

	public JTextField getTeacherIdTextField() {
		return teacherIdTextField;
	}

	public void setTeacherIdTextField(JTextField teacherIdTextField) {
		this.teacherIdTextField = teacherIdTextField;
	}

	public JTextField getTeacherNoTextField() {
		return teacherNoTextField;
	}

	public void setTeacherNoTextField(JTextField teacherNoTextField) {
		this.teacherNoTextField = teacherNoTextField;
	}

	public JTextField getTeacherNameTextField() {
		return teacherNameTextField;
	}

	public void setTeacherNameTextField(JTextField teacherNameTextField) {
		this.teacherNameTextField = teacherNameTextField;
	}


	public JRadioButton getRadioMan() {
		return radioMan;
	}

	public void setRadioMan(JRadioButton radioMan) {
		this.radioMan = radioMan;
	}

	public JRadioButton getRadioFemal() {
		return radioFemal;
	}

	public void setRadioFemal(JRadioButton radioFemal) {
		this.radioFemal = radioFemal;
=======

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import course.controller.CourseControllerListener;
import course.po.Teacher;

public class TeacherDialog extends JDialog{
	private static final long serialVersionUID = 1L;
	private CourseControllerListener  courseControllerListener;
	private JButton confirmButton;
	private JPanel teacherAddPanel;
	private Teacher teacher;
	private JTextField teacherIdTextField;
	private JTextField teacherNoTextField;
	private JTextField  teacherNameTextField;
	private JTextField teacherSexTextField;
	private JTextField  teacherAgeTextField;
	private JTextField  courseIdTextField;
	public TeacherDialog( TeacherJPanel owner, String title, Teacher teacher ){
		this.courseControllerListener = owner.getControllerListener();
		this.courseControllerListener.setTeacherAddDialog(this);
		this.setTitle(title);
		this.teacher = teacher;
		this.add(getTeacherAddPanel());
		this.setModal(true); // 设有模
		this.setSize(370, 530);
		this.setLocationRelativeTo(null);
		this.setResizable(false);
		this.setVisible(true);
		this.validate();
	}

	public void closeCurrentDialog() {
		this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);

	}

	/**
	 * 添加/修改表单面板
	 * 
	 * @return
	 */
	private JPanel getTeacherAddPanel() {
		teacherAddPanel = new JPanel();
		teacherAddPanel.setBackground(Color.orange);
		if ("添加教师".equals(this.getTitle())) {
			teacherIdTextField = new JTextField(30);
			teacherNoTextField = new JTextField(30);
			teacherNameTextField = new JTextField(30);
			teacherSexTextField = new JTextField(30);
			teacherAgeTextField = new JTextField(30);
			courseIdTextField = new JTextField(30);
			confirmButton = new JButton("确定添加");
			confirmButton.setActionCommand("addTeacherPost"); // 添加教师
		} else {
			teacherIdTextField = new JTextField(String.valueOf(teacher.getTeaId()), 30);
			teacherNoTextField = new JTextField(teacher.getTeaNo(), 30);
			teacherNameTextField = new JTextField(teacher.getTeaName(), 30);
			teacherSexTextField = new JTextField(teacher.getTeaSex(), 30);
			teacherAgeTextField = new JTextField(String.valueOf(teacher.getTeaAge()), 30);
			courseIdTextField = new JTextField(String.valueOf(teacher.getCourse().getCouId()), 30);
			confirmButton = new JButton("确定修改");
			confirmButton.setActionCommand("updateTeacherPost"); // 修改教师
		}
		confirmButton.addActionListener(courseControllerListener);
		teacherAddPanel.add(new JLabel("编号"));
		teacherAddPanel.add(teacherIdTextField);
		teacherAddPanel.add(new JLabel("教职工号"));
		teacherAddPanel.add(teacherNoTextField);
		teacherAddPanel.add(new JLabel("姓名"));
		teacherAddPanel.add(teacherNameTextField);
		teacherAddPanel.add(new JLabel("性别"));
		teacherAddPanel.add(teacherSexTextField);
		teacherAddPanel.add(new JLabel("年龄"));
		teacherAddPanel.add(teacherAgeTextField);
		teacherAddPanel.add(new JLabel("所教科目"));
		teacherAddPanel.add(courseIdTextField);
		teacherAddPanel.add(confirmButton);
		return teacherAddPanel;
	}

	public CourseControllerListener getCourseControllerListener() {
		return courseControllerListener;
	}

	public void setCourseControllerListener(CourseControllerListener courseControllerListener) {
		this.courseControllerListener = courseControllerListener;
	}

	public JButton getConfirmButton() {
		return confirmButton;
	}

	public void setConfirmButton(JButton confirmButton) {
		this.confirmButton = confirmButton;
	}

	public Teacher getTeacher() {
		return teacher;
	}

	public void setTeacher(Teacher teacher) {
		this.teacher = teacher;
	}

	public JTextField getTeacherIdTextField() {
		return teacherIdTextField;
	}

	public void setTeacherIdTextField(JTextField teacherIdTextField) {
		this.teacherIdTextField = teacherIdTextField;
	}

	public JTextField getTeacherNoTextField() {
		return teacherNoTextField;
	}

	public void setTeacherNoTextField(JTextField teacherNoTextField) {
		this.teacherNoTextField = teacherNoTextField;
	}

	public JTextField getTeacherNameTextField() {
		return teacherNameTextField;
	}

	public void setTeacherNameTextField(JTextField teacherNameTextField) {
		this.teacherNameTextField = teacherNameTextField;
	}

	public JTextField getTeacherSexTextField() {
		return teacherSexTextField;
	}

	public void setTeacherSexTextField(JTextField teacherSexTextField) {
		this.teacherSexTextField = teacherSexTextField;
>>>>>>> refs/remotes/origin/master
	}

	public JTextField getTeacherAgeTextField() {
		return teacherAgeTextField;
	}

	public void setTeacherAgeTextField(JTextField teacherAgeTextField) {
		this.teacherAgeTextField = teacherAgeTextField;
	}

	

	public JTextField getCourseIdTextField() {
		return courseIdTextField;
	}

	public void setCourseIdTextField(JTextField courseIdTextField) {
		this.courseIdTextField = courseIdTextField;
	}

	public void setTeacherAddPanel(JPanel teacherAddPanel) {
		this.teacherAddPanel = teacherAddPanel;
	}
	
}
